#include "BasicObjects.h"
/*******************************************************************
* Constructor
*******************************************************************/
BasicObjects::BasicObjects()
{

}
/*******************************************************************
* Destructor
*******************************************************************/
BasicObjects::~BasicObjects()
{

}
bool BasicObjects::initialize(ID3D10Device* pD3DDevice) {
	UINT numElementsInInputlayout = sizeof( vertexInputLayout ) / sizeof( vertexInputLayout[0] );

	/* Gen Cube */
	vertex v[8] = {		vertex( D3DXVECTOR3(-1,1,-1), D3DXVECTOR4(1,0,0,1),D3DXVECTOR2(0.0f, 0.0f) ),	//front top left
						vertex( D3DXVECTOR3(1,1,-1), D3DXVECTOR4(0,1,0,1),D3DXVECTOR2(1.0f, 0.0f) ),	//front top right
						vertex( D3DXVECTOR3(-1,-1,-1), D3DXVECTOR4(0,0,1,1),D3DXVECTOR2(0.0f, 1.0f) ),	//front bottom left
						vertex( D3DXVECTOR3(1,-1,-1), D3DXVECTOR4(1,1,0,1),D3DXVECTOR2(1.0f, 1.0f) ),	//front bottom right

						vertex( D3DXVECTOR3(-1,1,1), D3DXVECTOR4(1,0,0,1),D3DXVECTOR2(0.0f, 0.0f) ),	//back top left
						vertex( D3DXVECTOR3(1,1,1), D3DXVECTOR4(0,1,0,1),D3DXVECTOR2(1.0f, 0.0f) ),		//back top right
						vertex( D3DXVECTOR3(-1,-1,1), D3DXVECTOR4(0,0,1,1),D3DXVECTOR2(0.0f, 1.0f) ),	//back bottom left
						vertex( D3DXVECTOR3(1,-1,1), D3DXVECTOR4(1,1,0,1),D3DXVECTOR2(1.0f, 1.0f) )		//back bottom right
	};

	//create indexes for a cube 
	unsigned int i[36] = {	2,0,3,3,0,1,							
							3,1,7,7,1,5,							
							6,4,2,2,4,0,							
							7,5,6,6,5,4,							
							0,4,1,1,4,5,							
							6,2,7,7,2,3 };	
	//create mesh
	if ( FAILED( D3DX10CreateMesh( pD3DDevice, vertexInputLayout, numElementsInInputlayout, "POSITION", sizeof( v ) / sizeof( v[0] ), 6, D3DX10_MESH_32_BIT, &cubeMesh) ) ) return false;

	//insert data into mesh and commit changes
	cubeMesh->SetVertexData(0, v);
	cubeMesh->SetIndexData(i, 36);
	cubeMesh->CommitToDevice();
	/* Gen Pyramid */
	vertex v_pym[5] = {	vertex( D3DXVECTOR3(-1,1,-1), D3DXVECTOR4(1,0,0,1),D3DXVECTOR2(0.0f, 0.0f), D3DXVECTOR3(0,0,0) ),	//front top left
						vertex( D3DXVECTOR3(1,1,-1), D3DXVECTOR4(0,1,0,1),D3DXVECTOR2(1.0f, 0.0f), D3DXVECTOR3(0,0,0) ),	//front top right
						vertex( D3DXVECTOR3(-1,-1,-1), D3DXVECTOR4(0,0,1,1),D3DXVECTOR2(0.0f, 1.0f), D3DXVECTOR3(0,0,0) ),	//front bottom left
						vertex( D3DXVECTOR3(1,-1,-1), D3DXVECTOR4(1,1,0,1),D3DXVECTOR2(1.0f, 1.0f), D3DXVECTOR3(0,0,0) ),	//front bottom right

						vertex( D3DXVECTOR3(0,0,0), D3DXVECTOR4(1,0,0,1),D3DXVECTOR2(0.0f, 1.0f), D3DXVECTOR3(0,0,1) )		//peak
	};
	//create indexes for a Pyramid 
	unsigned int i_pym[18] = {
		0,2,1,1,2,3,
		2,3,4,
		0,2,4,
		0,4,1,						
		3,1,4		
		};	
	//create mesh
	if ( FAILED( D3DX10CreateMesh( pD3DDevice, vertexInputLayout, numElementsInInputlayout, "POSITION", sizeof( v_pym ) / sizeof( v_pym[0] ), 6, D3DX10_MESH_32_BIT, &pyramidMesh) ) ) return false;

	//insert data into mesh and commit changes
	pyramidMesh->SetVertexData(0, v_pym);
	pyramidMesh->SetIndexData(i_pym, 18);
	pyramidMesh->CommitToDevice();
	return true;
}
ID3DX10Mesh* BasicObjects::getCubeMesh() {
	return cubeMesh;
}
ID3DX10Mesh* BasicObjects::getPyramidMesh() {
	return pyramidMesh;
}
